<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>_待处理订单指定快递</title>
<!-- jedate -->
 <link rel="stylesheet" type="text/css" href="${ctx}/static/v2/js/plugins/jedate/skin/jedate.css"> 
 <script src="${ctx}/static/v2/js/plugins/jedate/jedate.js" type="text/javascript"></script>   
<script type="text/javascript">
	//锁定超区件
  var lockOutScopeOrderno = new Array();
  
  var single_array=new Array();
  var multi_array=new Array();
  var single_b_array=new Array();//单品时，每个批次的订单号
  var customerCode='';
  var companyCode='';
  var warehouseCode='';
  var psCompanyCode = '';
  var seCompanyCode = '';
  var psCurrentCompanyCode='';
  

  function query(){
     customerCode=$("#_customerCode").val();
     companyCode=$("#_companyCode").val();
     warehouseCode=$("#_warehouseCode").val();
     
//      if(!(!$("#_minWeight").val()&&!$("#_maxWeight").val())){
// 		 if(!$("#_minWeight").val()){
// 				$("#_minWeight").val('1');
// 		 }
				
// 		 if(!$("#_maxWeight").val()){
// 			$("#_maxWeight").val('1');
// 		 }
//      }
     if(!warehouseCode){
    	 jAlert("请选择仓库!","温馨提示");
    	 return;
     }
     psCompanyCode=$("#_psCompanyCode").val();
     if(companyCode=='-2' && (!psCompanyCode )){
    	 jAlert("必须选择派送快递!","温馨提示");
    	 return;
     }
    psCurrentCompanyCode = $("#_psCurrentCompanyCode").val();
    if (psCompanyCode == psCurrentCompanyCode) {
			jAlert("需要指派的快递不能和当前快递相同","温馨提示");
	}
     
    if("${isLockOutScopeOrderno}" != "on") {
	     var lockStr = "";
    	 $("input[name='single_myChecked']:checked").each(function(i,o){
        	 lockStr += $(o).val()+",";
         });
         $("input[name='multi_myChecked']:checked").each(function(i,o){
        	 lockStr += $(o).val()+",";
         });
         lockStr = lockStr.substring( 0 , lockStr.length-1 ); 
    	 $("#lockOutScopeOrdernoStr").val(lockStr);
     }
     $("#queryForm").submit();
  }

  var allIsLockOutScopeOrderno = null;
  $(function() {
	 $("#queryForm").validate(); 
	 $("input[type='checkbox']").attr("checked",false);
	 // $("#_fromDate").datepicker({ format:'yyyy-mm-dd'});
	 // $("#_toDate").datepicker({ format:'yyyy-mm-dd'});
	 jeDate({
		dateCell:"#_fromDate",  
		format:"YYYY-MM-DD hh:mm",
		isinitVal:true,
		isTime:true, 
		festival: true, //显示节日
		maxDate: jeDate.now(0), //1代表明天，2代表后天，以此类推
	})
	jeDate({
		dateCell:"#_toDate",  
		format:"YYYY-MM-DD hh:mm",
		isinitVal:true,
		isTime:true, 
		festival: true, //显示节日
		maxDate: jeDate.now(0), //1代表明天，2代表后天，以此类推
	})
	 customerCode='${customerCode}'; 
	 companyCode='${companyCode}'; 
	 seCompanyCode = companyCode;
	 companyCode=(companyCode=="-1"||companyCode=="-2")?"":companyCode;
	 warehouseCode='${warehouseCode}';
	 psCompanyCode='${psCompanyCode}';
	 
	 
// 	　使用jQuery实现 
	 $("#queryForm :input").change(function() {
		$("#queryForm").data("changed",true); 
	 });
	 
	 
	//是否锁定订单
	 var isLockOutScopeOrderno='${isLockOutScopeOrderno}';
	 if(isLockOutScopeOrderno=='on'){
		 $("#_lockOutScopeOrderno").iCheck('check'); 
	 }else{
		 $("#_lockOutScopeOrderno").iCheck('uncheck');
	 }
	 //绑定checkbox
	 bindCheckBox("myCheckedAll","myChecked");
	 
	 var  psCurrentCompanyCode = $("#_psCurrentCompanyCode").val();
	if (psCurrentCompanyCode == "TTKDEX"){
		$("#signPriorSend").css("display","inline-block");
	}else{
		$("#signPriorSend").css("display","none");
	}
	 
  });
  
  //显示or隐藏
  function showOrHide(flag,i){
	  var type;
	  if(flag==1){
		  type="single";
	  }else{
		  type="multi";
	  }
	  var temp=$("#"+type+"_batch_"+i);
	  
	  if(temp.css("display")=="table"){
		  temp.css("display","none");
	  }else{
		  $("[name='showOrHideDiv']").css("display","none");
		  temp.css("display","table");
	  }
	  
  }
  
  
 
	function count(orders,type) {
		var rs = new Array();
		var last_sku = '';
		var index = -1;
		for (var i = 0; i < orders.length; i++) {
			var orderno = orders[i];
			var sku = $("#" + type + orderno).html();
			if (last_sku != sku) {
				last_sku = sku;
				rs[++index] = 1;
			} else {
				rs[index] = rs[index] + 1;
			}
		}
		return rs;
	}

  
  //级联商家店铺
  function loadShop(customerCode,sel_shop){
	  $("#"+sel_shop).html("");
	  $.ajax({
			type : 'post',
			url : '${ctx}/warehouse/ajaxGetShop',
			data : {
				customerCode:customerCode
			},
			dataType : 'json',
			success : function(data) {
			    var shopList=data.shopList;
			    var str="<option value='' selected='selected'></option>";
				$.each(shopList, function(i) {
				    var shop=shopList[i];
				    str+="<option value='"+shop.shopCode+"'>"+shop.shopName+"</option>";
				});
				$("#"+sel_shop).html(str);
				$("#"+sel_shop).trigger("chosen:updated");
			},
			error : function() {
				jAlert("网络繁忙，请稍后重试...","温馨提示");
			}
		});
  }
  
  
	//当前快递选项为“天天快递”时，显示【标记为优先派送】按钮
	function selectCurrentCompanyCode() {
		var  psCurrentCompanyCode = $("#_psCurrentCompanyCode").val();
		if (psCurrentCompanyCode == "TTKDEX"){
			$("#signPriorSend").css("display","inline-block");
		}else{
			$("#signPriorSend").css("display","none");
		}
	}
	
	//标记为优先派送
	function signPriorSend() {
		var psFlag =$("#_psFlag").val();
		if (psFlag == 1){
			jAlert("当前快递已优先派送，请勿重复标记!", "错误提示");
			return false;
		}
		var selectedOrders = [];
		$("input[name='myChecked']:checked").each(function(i, o) {
			selectedOrders.push($(o).val());
		});
		if (selectedOrders.length == 0) {
			jAlert("请选择记录!", "错误提示");
			return false;
		}
		if (confirm('是否标记为优先派送！')) {
			showBg();
			$.ajax({
				type : 'post',
				url : '${ctx}/workBatch/signPriorSend',
				data : 'ordernos=' + selectedOrders ,
				dataType : 'json',
				timeout : 240000,
				success : function(data) {
					closeBg();
					if (data.status == "1") {
						jAlert(data.msg, "提示", function() {
							query();
						});
					} else {
						jAlert(data.msg, "提示", function() {
							query();
						});
					}
				},
				error : function() {
					closeBg();
					jAlert("服务器异常，请重试","错误提示");
				},

			});
		}
	}

	function assignCompany() {
		var selectedOrder = "";
		$("input[name='myChecked']:checked").each(function(i, o) {
			selectedOrder += $(o).val() + ",";
		});
		selectedOrder = selectedOrder.substring(0, selectedOrder.length - 1);
		if (selectedOrder == "") {
			jAlert("请至少选择一个订单", "温馨提示");
			return;
		}
		psCurrentCompanyCode = $("#_psCurrentCompanyCode").val();
		if (psCompanyCode == psCurrentCompanyCode) {
			jAlert("需要指派的快递不能和当前快递相同", "温馨提示");
		}
		jConfirm("所选订单分配快递 (" + psCompanyCode + ")  ,请确定操作!", "温馨提醒", function(
				result) {
			if (result) {

				$.ajax({
					type : 'post',
					url : '${ctx}/workBatch/assignCompany',
					data : 'selectedOrder=' + selectedOrder + "&psCompanyCode=" + psCompanyCode,
					dataType : 'json',
					success : function(data) {
						if (data.status == "success") {
							jAlert("分配成功!", "温馨提示", function() {
								query();
							});
						} else {
							jAlert(data.content, "温馨提示");
						}
					},
					error : function() {
						jAlert("获取信息错误！", "温馨提示");
					}
				});

			}
		});
	}
</script>
</head>

<body>


<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">条件查询</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

					
				 <form class="form-search" id="queryForm" method="post" action="${ctx}/workBatch/v2_query" style="margin-top: 10px;">
				 <input id="lockOutScopeOrdernoStr" name="_lockOutScopeOrdernoStr" type="hidden" value="${lockOutScopeOrdernoStr}" />
				 <input ID="_mergeOrder" name="_mergeOrder" type="hidden" value="true">
				 <input ID="_companyCode" name="_companyCode" type="hidden" value="-2">
				 
						     <div class="form-group row">
						    
							    <div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 商家: </span> 
										<select data-placeholder="请选择..." class="form-control searchSelect" id="_customerCode" name="_customerCode"  value="${param._customerCode}" onchange="ajaxAreaGroup(this,'_warehouseCode');loadShop(this.value,'_shopCode');">
											<option value=""></option>
											<c:forEach items="${customerList}" var="customer">
												<option value="${customer.customerCode}"
												  <c:if test="${customerCode eq customer.customerCode }">selected=selected</c:if>
												>${customer.customerName}</option>
											</c:forEach>
										</select>
									</div>
								</div>
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 店铺: </span> 
										<select class="form-control"  id="_shopCode" name="_shopCode"  value="${param._shopCode}"  >
											<option value=""></option>
											<c:forEach items="${shopList}" var="shop">
												<option value="${shop.shopCode}"
												  <c:if test="${param._shopCode eq shop.shopCode }">selected=selected</c:if>
												>${shop.shopName}</option>
											</c:forEach>
										</select>
									</div>
								</div>
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text">仓库: </span> 
										<select class="form-control"  name="_warehouseCode"  id="_warehouseCode" class="input-medium"  >
											<option value=""></option>
											<c:forEach items="${warehouseList}" var="w" >
											   <option value="${w.groupCode}"  <c:if test="${warehouseCode eq w.groupCode}">selected=selected</c:if> >${w.groupName}</option>
										   </c:forEach>
										</select>
									</div>
								</div>
								
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 目的地: </span> 
										<input type="text" name="_addres"  id="_addres" class="form-control span3" value="${param._addres}" >
									</div>
								</div>
								
								
							</div>
							<div class="form-group row">
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> &nbsp;审核时间: </span> 
										<input type="text" name="_fromDate" id="_fromDate"  value="${param._fromDate}" class="form-control required" > 
									</div>
								</div>
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 至: </span> 
										<input type="text" name="_toDate" id="_toDate"  value="${param._toDate}" class="form-control required">
									</div>
								</div>
								
								<!-- begin add 当前已指定快递  20160725 bug:439 -->
								<div class="col-sm-3" >
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 当前已指定快递: </span> 
										<select class="form-control"  id="_psCurrentCompanyCode" name="_psCurrentCompanyCode"  value="noAssign"  onchange = "selectCurrentCompanyCode();">
											<option value="noAssign">未指定</option>
											<option value="all">所有</option>
											<c:forEach items="${cmpList}" var="cmp">
												<c:if test="${'MJZT' ne cmp.companyCode }">
													<option value="${cmp.companyCode}" <c:if test="${param._psCurrentCompanyCode eq cmp.companyCode }">selected=selected</c:if>>${cmp.companyName}</option>
												</c:if>
											</c:forEach>
										</select>
									</div>
								</div>
								<!-- begin end 当前已指定快递  20160725 bug:439 -->
								
								<div class="col-sm-3" >
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 派送快递: </span> 
										<select class="form-control"  id="_psCompanyCode" name="_psCompanyCode"  value="${param._companyCode}"  >
											<option value="">----请选择----</option>
											<c:forEach items="${cmpList}" var="cmp">
												<c:if test="${'MJZT' ne cmp.companyCode }">
												<option value="${cmp.companyCode}"
												  <c:if test="${param._psCompanyCode eq cmp.companyCode }">selected=selected</c:if>
												>${cmp.companyName}</option>
												</c:if>
											</c:forEach>
										</select>
									</div>
								</div>
							</div>
							
							<div class="form-group row">
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 需要发票: </span> 
										<select class="form-control"   id="_isInvoice" name="_isInvoice" >
										    <option value="" >全部</option>
											<option value="1" <c:if test="${param._isInvoice eq '1'}">selected="selected"</c:if>>是</option>
											<option value="2" <c:if test="${param._isInvoice eq '2'}">selected="selected"</c:if>>否</option>
										</select>
									</div>
								</div>
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 是否优先派送: </span> 
										<select class="form-control"   id="_psFlag" name="_psFlag" >
										    <option value="-1"  <c:if test="${param._psFlag eq '-1'}">selected="selected"</c:if>>全部</option>
										    <option value="0"  <c:if test="${param._psFlag eq '0'}">selected="selected"</c:if>>否</option>
											<option value="1" <c:if test="${param._psFlag eq '1'}">selected="selected"</c:if>>是</option>
										</select>
									</div>
								</div>
							</div>
								<script type="text/javascript">
								
								Date.prototype.Format = function (fmt) { //author: meizz 
								    var o = {
								        "M+": this.getMonth() + 1, //月份 
								        "d+": this.getDate(), //日 
								        "h+": this.getHours(), //小时 
								        "m+": this.getMinutes(), //分 
								        "s+": this.getSeconds(), //秒 
								        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
								        "S": this.getMilliseconds() //毫秒 
								    };
								    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
								    for (var k in o)
								    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
								    return fmt;
								}
								<c:if test="${empty param._fromDate}">
									$("#_fromDate").val(new Date().Format("yyyy-MM-dd 00:00"));
								</c:if>
								<c:if test="${empty param._toDate}">
								$("#_toDate").val(new Date().Format("yyyy-MM-dd 23:59"));
								</c:if>
								</script>
							
							
							<div class="form-group row">
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 筛选范围: </span> 
										<select  class="form-control"  id="_scopeFilter" name="_scopeFilter">
											<option value="1" <c:if test="${param._scopeFilter eq '1'}">selected="selected"</c:if>>可达区域</option>
											<option value="2" <c:if test="${param._scopeFilter eq '2'}">selected="selected"</c:if>>超区件</option>
											<option value="3" <c:if test="${param._scopeFilter eq '3'}">selected="selected"</c:if>>优势区</option>
										</select>
									</div>
								</div>
								
								<div class="col-sm-3">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 重量(单位:g) </span> 
										<input  id="_minWeight" name="_minWeight"  class="form-control span2" value="${param._minWeight}"/>
										<span class="input-group-text"> 至: </span> 
										<input id="_maxWeight"   name="_maxWeight"  class="form-control span2" value="${param._maxWeight}"/>
										
									</div>
								</div>
								
								<div class="col-sm-2">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 锁定订单: </span> 
										<input type="checkbox" id="_lockOutScopeOrderno" name="_lockOutScopeOrderno" style="margin-top: -2px;"/>
									</div>
								</div>
									
								
								<div class="col-sm-1">
									<div class="input-group col-sm-12">
										<button class="btn btn-info" type="button" style="margin-left: 10px;" onclick="query(this);">搜索</button>
									</div>
								</div>
							
							</div>
					</form>

	</div>
	</div>
	</div>
	</div>
	
	
	
	
	<!-- 查询结果 start -->
	<div class="form-group row" >
	<div class="col-md-12">

	<div class="nav-tabs-custom">
		

		<div class="tab-content">
		
           
		       <form class="form-search" style="margin-top: 2px;" >
		         
				  <a  data-toggle="modal" role="button"  class="btn btn-primary" onclick="assignCompany();">确认分配快递</a>
				  <a id="signPriorSend"  data-toggle="modal" role="button"  class="btn btn-primary"  style="display:none"  onclick="signPriorSend();" >标记为优先派送</a>
		       </form>
				 <div style="height:10px;"></div>
				
				
				<table id="contentTable" class="table table-striped table-bordered table-condensed">
					<thead><tr>
					    <th>
					      <input type="checkbox" name="single_myCheckedAll" id="myCheckedAll" />
					    </th>
					    <th>序号</th>
					    <th>商家编码</th>
					    <th>订单号</th>
					    <th>来源店铺</th>
					    <th>收货人</th>
					    <th>目的地</th>
					    <th>指定快递公司</th>
					     <th>是否优先派送</th>
					    <th>审单时间 </th>
					    <th>sku </th>
					    <th>查询操作</th>
					</tr></thead>
				<tbody>
				<c:forEach items="${allOrderList}" var="o" varStatus="i">
					<tr id="tr_single_${o.ordeno}">
					   <td align="right">
						  <input type="checkbox" name="myChecked" id="single_${o.ordeno}" value="${o.ordeno}"  />
					   </td>
					   <td>${i.count}</td>
					   <td>${o.customerCode}</td>
					   <td id="single_ordeno_${o.ordeno}">${o.ordeno}</td>
					   <td id="single_shopna_${o.ordeno}">${o.shopna}</td>
					   <td id="single_recena_${o.ordeno}">${o.recena}</td>
					   <td id="single_addres_${o.ordeno}">${o.addres}</td>
					   <td id="single_cacode_${o.ordeno}">${o.cacode}</td>
					   <td id="single_psFlag_${o.ordeno}">
					       <c:if test="${o.prioritySendFlag eq '1'}">是</c:if>
					       <c:if test="${o.prioritySendFlag eq '0'}">否</c:if>
					   </td>
					   <td id="single_crtime_${o.ordeno}">${fn:substring(o.crtime,0,19)}</td>
					   <td id="single_sku_${o.ordeno}">${o.sku}</td>
					   <td>
				      	 <a href="#ordersDetailed" onclick="getAjaxOrders('${o.id}')" role="button" class="btn btn-small btn-primary" data-toggle="modal">订单详情 </a>
						 <a href="#itemsDetailed" onclick="getAjaxItems('${o.id}')" role="button" class="btn btn-small btn-primary" data-toggle="modal"> 商品详情 </a>
					   </td>
					</tr>
				</c:forEach>
				</tbody>
			    </table>


		</div>
		<!-- tab content -->

	</div>
	<!-- tab table -->
    
    </div>
    </div>
    	
    <!-- 订单详细信息  窗体--> 
    <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="ordersDetailed">
    		<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3>订单详细信息</h3>
					</div>
					<div class="modal-body" style="overflow: auto;height:500px;">
						<table class="table table-striped table-bordered table-condensed" id="modalBodyOrders"></table>
					</div>
					<div class="modal-footer">
					  <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
					</div>
				</div>
			</div>
		</div>

        <!-- 商品详细信息 窗体 --> 
		<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="itemsDetailed">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3>商品详细信息</h3>
					</div>
					<div class="modal-body" style="overflow: auto;">
						<table class="table table-striped table-bordered table-condensed" id="modalBodyItems"></table>
					</div>
					<div class="modal-footer">
					  <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
					</div>
				</div>
			</div>
		</div>
		
		
		</section>
		
</body>
</html>
